<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <p>Localstorage本地存储</p>
    <script>
        // localStorage添加数据
        localStorage.setItem('name','张三');
        localStorage.setItem('age',18);
        localStorage.setItem('gender','男');

        // 同名会覆盖
        localStorage.setItem('name','王五');

        // 获取数据个数、长度
        console.log(localStorage.length);

        // 获取指定数据信息
        console.log(localStorage.getItem('name'));  //方式1
        console.log(localStorage.name);  //方式2

        //如果名称不存在, 返回 null
        localStorage.removeItem('name222');  

        // localStorage 删除内容
        localStorage.removeItem("name");

        // 清空 localStorage 的数据
        localStorage.clear();

        // localStorage 的存储期限:除非手动删除，否则永久存储；




    </script>
</body>
</html>